from sqlalchemy import Column, String, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

# from config.getConfig import config

# 创建对象的基类:
Base = declarative_base()
# db_host = config('db')['host']
# db_port = config('db')['port']
# db_root = config('db')['root']
# db_password = config('db')['password']
# db_name = config('db')['name']
# 初始化数据库连接:
# 设置连接池连接1小时回收 localhost
engine = create_engine("mysql+mysqlconnector://root:729295@localhost:3306/record_day",
                       # echo=True,  # 设置为True，则输出sql语句
                       pool_size=5,  # 数据库连接池初始化的容量
                       max_overflow=100,  # 连接池最大溢出容量，该容量+初始容量=最大容量。超出会堵塞等待，等待时间为timeout参数值默认30
                       pool_recycle=3600  # 重连周期
                       )
# print(engine)
# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
# 创建session对象:
session = DBSession()

# 将expire_on_commit参数设为False
session.expire_on_commit = False
